package logic

import (
	"context"
	"house_srv/models/mysql"

	"house_srv/house_srv"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type FindHouseLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewFindHouseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FindHouseLogic {
	return &FindHouseLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *FindHouseLogic) FindHouse(in *house_srv.FindHouseRequest) (*house_srv.FindHouseResponse, error) {
	// todo: add your logic here and delete this line
	var house mysql.House
	err := house.Find(int(in.Id))
	if err != nil {
		return nil, err
	}

	one := house_srv.House{
		Name:    house.Name,
		Price:   float32(house.Price),
		Address: house.Address,
		Hav:     house.Hav,
		Img:     house.Img,
	}

	return &house_srv.FindHouseResponse{House: &one}, nil
}
